<cfsetting enablecfoutputonly="true">
<!--- Make sure all content to be outputed is wrapped in <cfoutput></cfoutput> tags. --->
<cfswitch expression="#thisTag.executionMode#">
	<cfcase value="start">
		<cfparam name="attributes.id" default="">
		<cfparam name="attributes.data" default="">
		<cfparam name="attributes.direction" default="horizontal">
		<cfparam name="attributes.setSize" default="3">
		<cfparam name="attributes.maxSets" default="">
		<cfparam name="attributes.setTag" default="div">
		<cfparam name="attributes.setClass" default="">
		<cfparam name="attributes.cellTag" default="span">
		<cfparam name="attributes.cellClass" default="">
		<cfparam name="attributes.delimiters" default=",">
		<cfparam name="attributes.module" default="">
		<cfparam name="attributes.path" default="">
		<cfparam name="attributes.moduleSet" default="">
		
		<!--- /* consider these mods or similar */
		
		
		
		horizontalAlign="left|center|right"
	    horizontalGap="8"
	    paddingBottom="0"
	    paddingTop="0"
	    verticalAlign="top|middle|bottom"
	    verticalGap="6"
		--->
		
		<cfif StructKeyExists(caller,'root')>
			<cfset root = caller.root>
		<cfelse>
			<cfset root = caller>
		</cfif>
		<cfif NOT thisTag.hasEndTag>
			<cfthrow detail="End tag required" message="All coop tags require an end tag." errorcode="sos.tag.attributes">
		</cfif>
		<cfif attributes.id EQ ''>
			<cfthrow detail="Missing required attribute: 'id'" message="'id' attribute is required">
		</cfif>
		<cfif !len(ATTRIBUTES.path)>
			<cfif len(ATTRIBUTES.moduleSet)>
				<cfset ATTRIBUTES.path = caller._api[ATTRIBUTES.moduleSet].get_modulePath()>
			<cfelse>
				<cfthrow detail="You must either declare a path for the module location or a module set if your framework supports this." message="either a path or module set must be delcared" type="coop.tag"/>
			</cfif>
		</cfif> 
		<cfscript>
		standardattributes = 'id,name,data,rowStart,rowEnd,cellTag,cellEnd,module,path'; // internally handled attributes
		attributes = root.coop.mergeattributes(attributes,root);
		attributeList = root.coop.createAttributeList(attributes,standardAttributes,root);
		if (!len(attributes.path)) {
			attributes.path = root.coop.get_sharePath();
		}
		</cfscript>
		<cfif NOT len(attributes.module)>
			<cfthrow message="Missing required attribute" detail="You must specify a value for the module attribute">
		</cfif>
	</cfcase>
	<cfcase value="end">
		<cfscript>
		_data = arrayNew(2);
		// Check to see if data is simple value and allow it to be passed in as generated content
		if (isSimpleValue(attributes.data) AND attributes.data EQ ''){
			attributes.data = thisTag.generatedContent;
			thisTag.generatedContent = '';
		}
		// Initialize the returnData object that we use for data handling
		returnData = createObject("component","#root.coop.get_shareClassPath()#objects.coop.returnData").init(attributes.data,attributes.delimiters);
		
		// get the number of records in the data passed into the returnData object
		recordCount = returnData.recordCount();
		
		// Remove any externally generated content.
		thisTag.generatedContent = '';
		setsPossible = ceiling(recordCount / attributes.setSize);
		if (attributes.direction EQ 'horizontal') {
			outerLoopLimit = setsPossible;
			innerLoopLimit = attributes.setSize;
			setIncrement = attributes.setSize;
			increment = 1;
		} else {
			outerLoopLimit = attributes.setSize;
			innerLoopLimit =setsPossible;
			setIncrement = 1;
			increment = attributes.setSize;
		}
		cellStart = 1;
		selectedCell = 1;
		for (iSet = 1; iSet LTE outerLoopLimit; iSet = iSet + 1) {
			if (attributes.direction EQ 'horizontal') {
				if (iSet GT 1) {
					cellStart = iSet + attributes.setSize;
				} 
			} else {
				cellStart = iSet;
				selectedCell = iSet;
			}
			for (iCell = 1; iCell LTE innerLoopLimit; iCell = iCell + 1) {
				if (selectedCell GT recordCount) {
					_data[iSet][iCell] = structNew();
				} else {
					_data[iset][iCell] = returnData.returnDataRowStruct(selectedCell);
				}
				selectedCell = selectedCell + increment;
			}
		}
		dataEnd = false;
		setEnd = false;
		</cfscript>
		<cfoutput>
		<div id="#attributes.id#"#attributeList#>
		</cfoutput>
		<cfloop from="1" to="#arrayLen(_data)#" index="i1">
			<cfset dataStart = false>
			<cfif i1 EQ 1>
				<cfset dataStart = true>
			<cfelseif i1 EQ arrayLen(_data)>
				<cfset dataEnd = true>
			</cfif>
			<cfloop from="1" to="#arrayLen(_data[i1])#" index="i2">
				<cfset setStart = false>
				<cfif i2 EQ 1>
					<cfset setStart = true>
					<cfset setEnd = false>
				<cfelseif i2 EQ arrayLen(_data[i1])>
					<cfset setEnd = true>
				</cfif>
				<cfset data = _data[i1][i2]>
				<cfmodule template="#attributes.path##attributes.module#.cfm" attributecollection="#data#">
			</cfloop>
		</cfloop>
		<cfoutput>
		</div>
		</cfoutput>
	</cfcase>
</cfswitch>
<cfsetting enablecfoutputonly="false">